package com.ciaojian.client.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ciaojian.client.service.DistUserServiceImpl;
import com.ciaojian.core.model.vo.UserDistributorChooseVo;
import com.ciaojian.core.util.Result;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @author oxiny
 */
@Api(tags = "用户模块: 分销员")
@Validated
@RestController
@RequestMapping("/user-distributor")
public class DistUserController {
    @Resource
    private DistUserServiceImpl distUserService;

    @ApiOperation("获取分销员客数")
    @GetMapping("/customer")
    public Result getCustomerByDistId(@NotNull(message = "分销员ID不能为空") Integer userId,
                                      @RequestParam(defaultValue = "0") Integer pageNo,
                                      @RequestParam(defaultValue = "6") Integer pageSize) {
        return Result.ok(distUserService.getCustomerByDistId(userId, new Page<>(pageNo, pageSize)));
    }

    @ApiOperation("获取佣金明细")
    @GetMapping("/record1")
    public Result getDistRecord1(@NotNull(message = "分销员ID不能为空") Integer userId,
                                @RequestParam(defaultValue = "0") Integer pageNo,
                                @RequestParam(defaultValue = "6") Integer pageSize) {
        return Result.ok(distUserService.getDistRecord(userId, new Page<>(pageNo, pageSize)));
    }

    @ApiOperation("获取分销员客数首次消费数量")
    @GetMapping("/record")
    public Result getOrderRecord(@NotNull(message = "分销员ID不能为空") Integer userId) {
        return Result.ok(distUserService.getOrderRecord(userId));
    }

    /**
     * 3
     * @param userId
     * @return
     */
    @ApiOperation("分销员数据")
    @GetMapping("/data")
    public Result data(@NotNull(message = "分销员ID不能为空") Integer userId) {
        return Result.ok(distUserService.data(userId));
    }

    @ApiOperation("查询用户是否可以成为分销员")
    @GetMapping("/check-limit")
    public Result canApply(@NotNull(message = "userId不能为空") @ApiParam("用户ID") Integer userId) {
        return Result.ok(distUserService.checkByTargetId(userId));
    }

    @ApiOperation("申请成为分销员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "form")
    })
    @PostMapping("/apply")
    public Result apply(@NotNull(message = "userId不能为空") Integer userId) {
        distUserService.apply(userId);
        return Result.ok();
    }

    @ApiOperation("获取奖券信息")
    @GetMapping("/coupon-info/{distributorId}")
    public Result get(@PathVariable Integer distributorId) {
        return Result.ok(distUserService.findCouponAndStoreAvailableById(distributorId));
    }

    @ApiOperation("被分享用户选择奖励")
    @PostMapping
    public Result choose(@RequestBody UserDistributorChooseVo params) {
        distUserService.choose(params);
        return Result.ok();
    }
}
